package com.itcat.controller;/*
 * @Author: gonhsl
 * @Date:2022-04-02-1:08
 * */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.OmsOrderReturnReason;
import com.itcat.service.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    /**
     * Description:
     * date: 2022/4/2 1:09
     *
     * @author: chp
     * @since JDK 1.8
     */
    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;

    @GetMapping("/list")
    public CommonResult list(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        Page<OmsOrderReturnReason> page = new Page<>(pageNum, pageSize);
        Page<OmsOrderReturnReason> pageInfo = omsOrderReturnReasonService.findList(page);
        CommonPage<OmsOrderReturnReason> result = CommonPage.restPage(pageInfo);

        return CommonResult.success(result, "");

    }
    /**
     * Description:添加退货原因
     * date: 2022/4/2 20:06
     * @author: chp
     * @since JDK 1.8
     */
   @PostMapping("/create")
    public CommonResult  create(@RequestBody OmsOrderReturnReason returnReason){
       omsOrderReturnReasonService.create(returnReason);
return CommonResult.success();
   }

    /**
     * Description:批量删除退货原因
     * date: 2022/4/2 20:06
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids) {
        omsOrderReturnReasonService.delete(ids);
        return CommonResult.success();
    }

    /**
     * Description:修改退货原因启用状态
     * date: 2022/4/2 20:06
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/status")
    public CommonResult updateStatus(@RequestParam List<Integer> ids,@RequestParam Integer status) {

        omsOrderReturnReasonService.updateStatus(ids,status);
        return CommonResult.success();
    }

    /**
     * Description:修改退货原因启用状态
     * date: 2022/4/2 20:06
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@RequestBody OmsOrderReturnReason returnReason,@PathVariable Integer id) {

        omsOrderReturnReasonService.update(returnReason, id);
        return CommonResult.success();
    }

    /**
     * Description:获取单个退货原因详情信息
     * date: 2022/4/2 20:06
     *
     * @author: chp
     * @since JDK 1.8
     */
    @GetMapping("/{id}")
    public CommonResult One( @PathVariable Integer id) {

        OmsOrderReturnReason one = omsOrderReturnReasonService.findOne(id);
        return CommonResult.success(one);
    }
}
